<template>
  <div class="preview-container">
    <div class="nav-stu">
      <span>{{ realName }}</span>
      {{ avatar }}
    </div>
    <div class="intro-section">
      <div class="intro-header">
        <!-- <i class="el-icon-reading"></i> -->
         <img src="images/jh.png" width="180px" style="margin-bottom: 20px;" alt="">
        <h1>实有人口管理</h1>
      </div>
      <div class="intro-content">
        <div class="intro-card">
          <!-- <i class="el-icon-warning-outline"></i> -->
          <p>在电脑屏幕展示20个本辖区人员人像。</p>
          <p>每答对1个计0.5分，在电脑上作答，答出姓氏即可，限时20分钟，依正确数计分。</p>
        </div>
      </div>
    </div>
    <div class="start-button-container">
      <div class="start-button-wrapper" @click="handleCreate">
        <div class="start-button">
          <!-- <i class="el-icon-video-play"></i> -->
          <span>{{ loadingText }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { fetchDetail } from "@/api/exam/exam";
import {  createPaperPop } from "@/api/paper/exam";
import { mapGetters } from "vuex";

export default {
  name: "PreExam",
  data() {
    return {
      examId: "",
      loading: false,
      loadingText: "实有人口管理",
      postForm: {
        title: "实有人口管理",
        totalTime: 100,
        objScore: 0,
        subjScore: 0,
        totalScore: 100,
        qualifyScore: 60,
        content:
          "实有人口考核输入目标人物的姓氏",
      },
    };
  },

  created() {
    this.examId = this.$route.params.examId;
    // this.fetchData(this.examId)
  },
  
  computed:{
    ...mapGetters([
      'avatar',
      'realName',
      'address'
    ])
  },

  methods: {
    showLoading() {
      this.loading = true;
      this.loadingText = "加载中";
    },

    closeLoading() {
      this.loading = false;
      this.loadingText = "实有人口管理";
    },

    fetchData(id) {
      fetchDetail(id).then((response) => {
        this.postForm = response.data;
      });
    },

    handleCreate() {
      const params = { examId: this.examId };
      const ctx = this;

      this.showLoading();

      createPaperPop(params).then((response) => {
        console.log(response);

        if (response.code === 0) {
          // ctx.$message({
          //   message: "试卷创建成功，即将进入考试！",
          //   type: "success",
          // });

          setTimeout(function () {
            ctx.$router.push({
              name: "StartPopExam",
              params: { id: response.data.id },
            });
          }, 2000);
        } else if(response.code == 5){
          ctx.$message.warning("当前项已结束，即将进入下一项...")
          setTimeout(()=>{
            ctx.$router.push({name:'SafetyExam'})
          },1000)
        }else {
          ctx.$message.error(response.data.msg);
          this.closeLoading();
        }
      });

    
    },

    handleBack() {
      window.location.href = document.referrer;
    },
  },
};
</script>

<style scoped>
.preview-container {
  min-height: 100vh;
  /* background: linear-gradient(135deg, #f5f7fa 0%, #e4e7ed 100%); */
  background-image: url("/images/bg/bg_12_16.jpg");
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.nav-stu {
  width: 100%;
  display: flex;
  justify-content: end;
  font-size: 30px;
  /* color: #3c3a3a; */
  color: rgb(255, 194, 145);

}

.nav-stu span {
  /* color: #3c3a3a; */
  margin-right: 20px;
}

.intro-section {
  max-width: 1400px;
  width: 100%;
  margin-bottom: 50px;
  color: rgb(255, 194, 145);
}

.intro-header {
  text-align: center;
  margin-bottom: 40px;
  color: rgb(255, 194, 145);
}

.intro-header i {
  font-size: 40px;
  /* color: #409EFF; */
  margin-bottom: 15px;
}

.intro-header h1 {
  /* color: #303133; */
  font-size: 32px;
  margin: 0;
}

.intro-content {
  /* display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 20px; */
  padding: 0 20px;

}

.intro-card {
  /* background: white; */
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  text-align: center;
  transition: transform 0.3s ease;
  color: rgb(255, 194, 145);
  
}

.intro-card:hover {
  transform: translateY(-5px);
}

.intro-card i {
  font-size: 30px;
  color: #409eff;
  margin-bottom: 15px;
}

.intro-card p {
  /* color: #606266; */
  margin: 0;
  font-size: 30px;
  line-height: 1.6;
  text-align: start;
}

.start-button-container {
  margin-top: 30px;
}

.start-button-wrapper {
  cursor: pointer;
  padding: 10px;
}

.start-button {
  width: 200px;
  height: 60px;
  /* border-radius: 50%; */
  border-radius: 20px;
  background: linear-gradient(145deg, #409eff, #36a3ff);
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  transition: all 0.3s ease;
  box-shadow: 0 6px 16px rgba(64, 158, 255, 0.4);
}

.start-button:hover {
  transform: scale(1.05);
  box-shadow: 0 8px 20px rgba(64, 158, 255, 0.6);
}

.start-button i {
  font-size: 40px;
  margin-bottom: 10px;
}

.start-button span {
  font-size: 16px;
  font-weight: bold;
}
</style>